package me.sdevil507.platform.po;


import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import me.sdevil507.supports.jpa.BaseJpaSnowflakeIdAndAuditEntity;
import org.hibernate.annotations.Where;
import org.springframework.boot.context.properties.bind.DefaultValue;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 平台资源表[PlatResourcePo]
 *
 * @author sdevil507
 * created on 2020-06-23 18:43:30
 */
@Entity
@Table(name = "plat_resource")
@Data
@EqualsAndHashCode(callSuper = true, exclude = {"resourceRel"})
@ToString(exclude = {"resourceRel"})
public class PlatResourcePo extends BaseJpaSnowflakeIdAndAuditEntity {

    /**
     * 名称
     */
    @Column
    private String title;

    /**
     * 资源编码
     */
    @Column
    private String code;

    /**
     * 资源类型
     * <p>
     * 1:菜单
     * 2:按钮
     */
    @Column
    private Integer type;

    /**
     * 资源分类
     * <p>
     * 1:平台端
     * 2:服务端
     * 3:机构端
     * 4:专家端
     */
    @Column
    private Integer classify;

    /**
     * 服务分类
     * <p>
     * 1:智库管理
     * 2:专家管理
     * 3:课题管理
     * 4:其他工具
     */
    @Column
    private Integer serviceClassify;

    /**
     * 同级排序
     */
    @Column
    private Integer sortNum = 1;

    /**
     * 路径
     */
    @Column
    private String path;

    /**
     * 图标
     */
    @Column
    private String iconSvg;

    /**
     * 标签
     */
    @Column
    private String tags;

    /**
     * 描述
     */
    @Column
    private String description;

    /**
     * 父id
     */
    @Column
    private Long parentId;

    /**
     * 是否展开
     */
    @Column(columnDefinition = "bit(1) default 1")
    private boolean expand;

    /**
     * 子资源
     */
    @OneToMany(cascade = CascadeType.REMOVE)
    @JoinColumn(name = "parentId", foreignKey = @ForeignKey(name = "none"))
    @OrderBy("sortNum ASC")
//    @Where(clause = "type != 2")
    private List<PlatResourcePo> children = new ArrayList<>();

    /**
     * 子模块
     */
    @OneToMany(cascade = CascadeType.REMOVE)
    @JoinColumn(name = "parentId", foreignKey = @ForeignKey(name = "none"))
    @OrderBy("sortNum ASC")
    private List<PlatResourcePo> subModules = new ArrayList<>();

}